home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.2 Applications 1996 May / SGI IRIX 6.2 Applications 1996 May.iso / dist / impr_dev.idb / usr / impressario / src / examples / libspool / queue.c.z / queue.c
C/C++ Source or Header  |  1996-05-06  |  5KB  |  185 lines

  1. /**************************************************************************
  2.  *                                      *
  3.  *           Copyright (c)    1991 Silicon Graphics, Inc.          *
  4.  *            All Rights Reserved                    *
  5.  *                                      *
  6.  *       THIS    IS UNPUBLISHED PROPRIETARY SOURCE CODE OF SGI          *
  7.  *                                      *
  8.  * The copyright notice above does not evidence any actual of intended      *
  9.  * publication of such source code, and is an unpublished work by Silicon *
  10.  * Graphics, Inc. This material contains CONFIDENTIAL INFORMATION that is *
  11.  * the property of Silicon Graphics, Inc. Any use, duplication or      *
  12.  * disclosure not specifically authorized by Silicon Graphics is strictly *
  13.  * prohibited.                                  *
  14.  *                                      *
  15.  * RESTRICTED RIGHTS LEGEND:                          *
  16.  *                                      *
  17.  * Use, duplication or disclosure by the Government is subject to      *
  18.  * restrictions as set forth in subdivision (c)(1)(ii) of the Rights in      *
  19.  * Technical Data and Computer Software clause at DFARS 52.227-7013,      *
  20.  * and/or in similar or successor clauses in the FAR, DOD or NASA FAR      *
  21.  * Supplement. Unpublished - rights reserved under the Copyright Laws of  *
  22.  * the United States. Contractor is SILICON GRAPHICS, INC., 2011 N.      *
  23.  * Shoreline Blvd., Mountain View, CA 94039-7311              *
  24.  **************************************************************************
  25.  *
  26.  * File: queue.c
  27.  *
  28.  * Description: Prints the job queue for the specified printer.
  29.  *
  30.  **************************************************************************/
  31.  
  32.  
  33. #ident "$Revision: 1.2 $"
  34.  
  35.  
  36. #include <stdio.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <time.h>
  40. #ifdef sgi
  41. #include <getopt.h>
  42. #endif
  43. #include "spool.h"
  44.  
  45.  
  46. char *pname;
  47. int spooler = SL_SPOOLER_NONE;        /* Indicate that no spooler is set */
  48. int queue_type = SL_QUEUE_MERGED;    /* Default to local + remote queue */
  49.  
  50.  
  51. extern char *optarg;
  52. extern int optind;
  53.  
  54.  
  55. int queue_info(SLQueueStruct*);        /* Display queue information */
  56. void usage(char*);
  57.  
  58.  
  59. main(int argc, char *argv[])
  60. {
  61.     int i, ch, num, ret;
  62.     int errflag = 0;
  63.     SLPrinterStruct *ptr;        /* Refer to SLGetPrinterList(3) */
  64.     SLQueueStruct *queue, *qptr;    /* Refer to SLGetQueue(3) */
  65.  
  66.     /*
  67.      * Process command line args
  68.      */
  69.     while ((ch = getopt(argc, argv, "s:q:")) != -1) {
  70.     switch (ch) {
  71.         case 's':        /* Spooler to use */
  72.         if (!strcmp(optarg, "bsd"))
  73.             spooler = SL_SPOOLER_BSD;
  74.         else if (!strcmp(optarg, "sysv"))
  75.             spooler = SL_SPOOLER_SYSV;
  76.         else
  77.             errflag++;
  78.         break;
  79.         case 'q':        /* Queue type */
  80.         if (!strcmp(optarg, "local"))        /* Local queue only */
  81.             queue_type = SL_QUEUE_LOCAL;
  82.         else if (!strcmp(optarg, "remote"))    /* Remote queue only */
  83.             queue_type = SL_QUEUE_REMOTE;
  84.         else if (!strcmp(optarg, "merged"))    /* Both queues */
  85.             queue_type = SL_QUEUE_MERGED;
  86.         else
  87.             errflag++;
  88.         break;
  89.         case '?':
  90.         default:
  91.         errflag++;
  92.         break;
  93.     }
  94.     }
  95.  
  96.     /*
  97.      * If error, print usage and exit
  98.      */
  99.     if (errflag) {
  100.     usage(argv[0]);
  101.     exit(1);
  102.     }
  103.  
  104.     /*
  105.      * If a spooling system has been specified set it
  106.      */
  107.     if (spooler != SL_SPOOLER_NONE) {
  108.     if (SLSetSpooler(spooler) < 0) {
  109.         SLPerror(argv[0]);
  110.         exit(1);
  111.     }
  112.     }
  113.  
  114.     /*
  115.      * Get the printer name. If no printer name is specified, use
  116.      * the default printer
  117.      */
  118.     if (argc == optind) {
  119.     if (SLGetDefPrinterName(&pname) < 0) {
  120.         SLPerror(argv[0]);
  121.         exit(1);
  122.     }
  123.     } else
  124.     pname = argv[optind];
  125.  
  126.     /*
  127.      * Get the printer information. This is needed for SLGetQueue
  128.      */
  129.     if (SLGetPrinterInfo(pname, &ptr) < 0) {
  130.         SLPerror(argv[0]);
  131.         exit(1);
  132.     }
  133.  
  134.     /*
  135.      * Get the queue for this printer. If we get a SL_ERR_REMOTE
  136.      * error then we retry the call again in case the error was
  137.      * generated by transitory network problems.
  138.      */
  139.     if ((ret = SLGetQueue(ptr, queue_type, &queue, &num)) < 0)
  140.     if (SLerrno == SL_ERR_REMOTE)
  141.             ret = SLGetQueue(ptr, queue_type, &queue, &num);
  142.     if (ret < 0) {
  143.         int j, status, nout;
  144.         char **out_buf;
  145.         SLPerror(argv[0]);
  146.         if ((status = SLGetSpoolerError(&out_buf, &nout)) != 0) {
  147.             (void)fprintf(stderr, "Spooler exit status: %d\n", status);
  148.             (void)fprintf(stderr, "Spooler error message(s):\n");
  149.             for (j = 0; j < nout; j++)
  150.                 (void)fprintf(stderr, "\t%s\n", out_buf[j]);
  151.         }
  152.         exit(1);
  153.     }
  154.  
  155.     /*
  156.      * Print the queue
  157.      */
  158.     (void)printf("Queue for %s (%d jobs):\n", ptr->local_name, num);
  159.     for (i = 0, qptr = queue; i < num; i++, qptr++)
  160.         queue_info(qptr);
  161.  
  162.     return 0;
  163. }
  164.  
  165.  
  166. int queue_info(SLQueueStruct *ptr)
  167. {
  168.     (void)printf("\n");
  169.     (void)printf("\tJob ID:\t%s\n", ptr->job_id);
  170.     (void)printf("\tOwner:\t%s\n", ptr->username);
  171.     (void)printf("\tTitle:\t%s\n", ptr->title ? ptr->title : "Unknown");
  172.     (void)printf("\tSize:\t%u\n", ptr->size);
  173.     (void)printf("\tQueue:\t%s\n", (ptr->is_local) ? "local": "remote");
  174.     (void)printf("\tTime:\t%s", (ptr->time_stamp) ?
  175.                     ctime(&ptr->time_stamp): "Unknown\n");
  176. }
  177.  
  178.  
  179. void usage(char *progname)
  180. {
  181.     (void)fprintf(stderr,
  182.     "%s [-s bsd | sysv] [-q local | remote | merged] [printer_name]\n",
  183.     progname);
  184. }
  185.